package com.yuandian.middle.platform.contoller;

import com.yuandian.api.middle_platform.po.OrgAbilityParam;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.middle.platform.service.IOrgAbilityOverviewService;
import com.yuandian.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 说明：单位能力总览controller
 * @Author tianlr
 * @Date 2023/5/16 10:11
 */
@Api(value = "orgAbilityOverview", tags = "单位能力总览接口")
@RestController
@RequestMapping("/modules/orgAbilityOverview")
public class OrgAbilityOverviewController {
    @Autowired
    private IOrgAbilityOverviewService orgAbilityOverviewService;

    /**
     * 查询单位
     * @return
     */
    @PostMapping("/queryOrg")
    @ApiOperation(value = "查询单位", notes = "查询单位")
    public R queryOrg(@RequestBody OrgAbilityParam param) {
        return orgAbilityOverviewService.selectDataOrg(param);
    }

    /**
     * 作为能力提供方，查询能力数、使用方数、订购单量
     * @return
     */
    @PostMapping("/queryDataByProvider")
    @ApiOperation(value = "查询能力数、使用方数、订购单量", notes = "作为能力提供方，查询能力数、使用方数、订购单量，必填参数：orgCode")
    public R queryDataByProvider(@RequestBody OrgAbilityParam param) {
        if (param == null || StringUtils.isEmpty(param.getOrgCode())) {
            return R.failed("传入参数不正确！orgCode不能为空");
        }
        return orgAbilityOverviewService.selectDataByProvider(param);
    }

    /**
     * 作为能力使用方，查询能力数、订购单量
     * @return
     */
    @PostMapping("/queryDataByUser")
    @ApiOperation(value = "查询能力数、订购单量", notes = "作为能力使用方，查询能力数、订购单量，必填参数：orgCode")
    public R queryDataByUser(@RequestBody OrgAbilityParam param) {
        if (param == null || StringUtils.isEmpty(param.getOrgCode())) {
            return R.failed("传入参数不正确！orgCode不能为空");
        }
        return orgAbilityOverviewService.selectDataByUser(param);
    }

    /**
     * 查询能力对应的使用方数、订购单量
     * @return
     */
    @PostMapping("/queryDataByAbility")
    @ApiOperation(value = "查询能力对应的使用方数、订购单量", notes = "查询能力对应的使用方数、订购单量，必填参数：abilityCode")
    public R queryDataByAbility(@RequestBody OrgAbilityParam param) {
        if (param == null || StringUtils.isEmpty(param.getAbilityCode())) {
            return R.failed("传入参数不正确！abilityCode不能为空");
        }
        return orgAbilityOverviewService.selectDataByAbility(param, 1);
    }
}
